package com.wwtech.epp.view;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.wwtech.epp.R;
import com.wwtech.epp.ui.activity.friend.AddGroupActivity;
import com.wwtech.epp.ui.activity.work.NewProjectActivity;
import com.wwtech.epp.ui.activity.work.ProductManageActivity;
import com.wwtech.epp.ui.activity.work.ProjectReportActivity;

import static com.wwtech.epp.R.id.re_addfriends;
import static com.wwtech.epp.R.id.re_chatroom;

public class MorePopWindow extends PopupWindow {
    @SuppressLint("InflateParams")
    public MorePopWindow(final Activity context) {
        LayoutInflater inflater = (LayoutInflater) context
                                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View content = inflater.inflate(R.layout.popupwindow_add, null);

        // 设置SelectPicPopupWindow的View
        this.setContentView(content);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);

        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimationPreview);


        RelativeLayout start_chat = (RelativeLayout) content.findViewById(R.id.start_chat);
        RelativeLayout newproject = (RelativeLayout) content.findViewById(re_chatroom);
        RelativeLayout projectManager = (RelativeLayout) content.findViewById(re_addfriends);
        RelativeLayout huibao = (RelativeLayout) content.findViewById(R.id.huibao);
//        if (ContainValue.userLogin.getData().getRoleLevel() > 1) {
//            huibao.setVisibility(View.GONE);
//        }
        start_chat.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, AddGroupActivity.class);
                intent.putExtra("title", "发起聊天");
                context.startActivity(intent);
                MorePopWindow.this.dismiss();
            }
        });
        projectManager.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ProductManageActivity.class);
                context.startActivity(intent);
                MorePopWindow.this.dismiss();

            }

        });
        newproject.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, NewProjectActivity.class);
                context.startActivity(intent);
                MorePopWindow.this.dismiss();
            }

        });
        huibao.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ProjectReportActivity.class);
                intent.putExtra("title", "项目汇报");
                context.startActivity(intent);
                MorePopWindow.this.dismiss();
            }

        });

    }

    /**
     * 显示popupWindow
     *
     * @param parent
     */
    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            this.showAsDropDown(parent, 0, 25);
        } else {
            this.dismiss();
        }
    }
}
